package com.yc.chaoshi.cs_manage.controller;


import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.chaoshi.cs_manage.mapper.PmsFenlei1Mapper;
import com.yc.chaoshi.entity.PmsFenlei1;
import com.yc.chaoshi.entity.PmsGoods;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xz
 * @since 2022-08-04
 */
@RestController
@RequestMapping("/chaoshi/pmsFenlei1")
public class PmsFenlei1Controller {

    @RequestMapping("/")
    public String hello(){
        return "hello world!";
    }
    @Resource
    private PmsFenlei1Mapper fenlei1Mapper;

    @RequestMapping("selectFenlei1")
    public Page selectFenlei1(@RequestParam(defaultValue = "") String aname,
                            @RequestParam(defaultValue = "1") int page){
        Page<PmsFenlei1> ipage = new Page<>(page,10);
        ipage.orders().add(OrderItem.asc("aid"));
        System.out.println(fenlei1Mapper.selectfenlei1(aname, (page - 1) * 10,10));
        ipage.setRecords(fenlei1Mapper.selectfenlei1(aname, (page - 1) * 10,10));
        System.out.println(fenlei1Mapper.selectfenlei1(aname,0,1000).size());
        long total = fenlei1Mapper.selectfenlei1(aname,0,1000).size();
        ipage.setTotal(total);
        return ipage;
    }

    @RequestMapping("deleteFenlei1")
    public int deleteFenlei1(@RequestParam int aid){
        fenlei1Mapper.deletefenlei1(aid);
        return 0;
    }

    @RequestMapping("insertFenlei1")
    public int insertFenlei1(@RequestParam String aname,
                             @RequestParam int display,
                             @RequestParam String des){
        fenlei1Mapper.insertfenlei1(aname, display, des);
        return 0;
    }

    @RequestMapping("updateFenlei1")
    public int updateFenlei1(@RequestParam String aname,
                           @RequestParam int display,
                           @RequestParam String des,
                           @RequestParam int aid) {
        fenlei1Mapper.updatefenlei1(aname, display, des, aid);
        return 0;
    }
}

